/* Author: David McCoy dave.mccoy@cospandesign.com
 *
 *     This file is part of DLCM\SubServ.
 *
 *  DLCM\SubServ is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  DLCM\SubServ is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with DLCM\SubServ.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * TCPGenerator.java
 *
 * Class used to generate a TCP provider for a PubSub
 * 
 */
package com.cospandesign.gui.providers.tcp;

import com.cospandesign.gui.providers.ProviderGuiGenerator;
import java.util.HashMap;


public class TCPGenerator extends ProviderGuiGenerator {

   public boolean LocalHostFlag = false;
   public String NetworkName;
   public String PortNumber;
   public String TestPortNumber;


   public TCPGenerator (){
       NetworkName = new String ("");
       PortNumber = new String ("");
       TestPortNumber = new String ("7600");
   }
/*
   private PropertyChangeSupport support = new PropertyChangeSupport(this);

   public void addPropertyChangeListener(PropertyChangeListener listener ) {
      this.support.addPropertyChangeListener( listener );
   }

   public void removePropertyChangeListener(PropertyChangeListener listener ) {
      this.support.removePropertyChangeListener( listener );
   }
*/
   public String getNetworkName() {
       if (this.LocalHostFlag){
           return "127.0.0.1";
       }
      return NetworkName;
   }

   public void setNetworkName(String NetworkName) {
      //String old = this.NetworkName;
      this.NetworkName = NetworkName;
      //support.firePropertyChange("Network Name", old, NetworkName);
   }

   public String getPortNumber(){
      return PortNumber;
   }

   public void setPortNumber(String PortNumber){
      //String old = this.PortNumber;
       Integer num = Integer.parseInt(PortNumber);
       if (num == null){
           PortNumber = "7600";
       }
       if ((num > 655535) || (num < 0)){
           PortNumber = "7600";
       }
      this.PortNumber = PortNumber;
      //support.firePropertyChange("Port Number", old, PortNumber);
   }

   @Override
   public HashMap<String, String> getProviderVariables() {

        HashMap<String, String> ProviderMap = new HashMap<String, String>();
        
        //String network = new String ()

        ProviderMap.put("protocol", "tcpq");
        ProviderMap.put("network", getNetworkName() + ":" + TestPortNumber);
        //Integer pn = Integer.parseInt(TestPortNumber);
        //pn++;
        //TestPortNumber = pn.toString();
        //Integer portNumber = Integer.getInteger(getPortNumber());
        //portNumber++;

        //setPortNumber(portNumber.toString());

        return ProviderMap;
   }


}
